package com.rui.framework.beans.factory.support;

import com.rui.framework.beans.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : SimpleBeanDefinitionRegistry
 * @createTime : [2022/2/26 15:52]
 * @description : [描述该类的功能]
 */

@SuppressWarnings("all")
public class SimpleBeanDefinitionRegistry implements BeanDefinitionRegistry {

    /**
     * 定义一个容器，用来存储BeanDefinition对象
     */
    private Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();

    /**
     * 住的BeanDefinition对象到注册表中
     *
     * @param beanName
     * @param beanDefinition
     */
    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);
    }

    /**
     * 从注册表中删除指定名称的BeanDefinition对象
     *
     * @param beanName
     */
    @Override
    public void removeBeanDefinition(String beanName) throws Exception {
        beanDefinitionMap.remove(beanName);
    }

    /**
     * 根据名称从注册表中获取BeanDefinition对象
     *
     * @param beanName
     */
    @Override
    public BeanDefinition getBeanDefinition(String beanName) throws Exception {
        return beanDefinitionMap.get(beanName);
    }

    @Override
    public boolean containsBeanDefinition(String beanName) {
        return beanDefinitionMap.containsKey(beanName);
    }

    @Override
    public int getBeanDefinitionCount() {
        return beanDefinitionMap.size();
    }

    @Override
    public String[] getBeanDefinitionNames() {
        return beanDefinitionMap.keySet().toArray(new String[0]);
    }
}
